<template>
  <div class="checkSheep">
    <div class="left">
      <div class="navs" v-for="(item, index) in navs" :key="item.id">
        <div class="nav_item" :class="{ on: currentNav === index }" @click="handleCheckNav(index)">
          <img src="@/assets/img/check.png" alt="" class="bian" :class="{ on: currentNav === index }" />
          <p>{{ item.name }}</p>
          <span>(1/90)</span>
        </div>
        <div class="checkbox" :class="{ on: currentNav === index }">
          <van-checkbox @click="handleCheckBox(item)" icon-size="18px" v-model="item.check" checked-color="#37B5B5"></van-checkbox>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="nos">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了">
          <div
            class="no_item"
            @click="handleCheckNo(index)"
            :class="{ on: sheep.check }"
            v-for="(sheep,index) in sheeps"
            :key="sheep.id"
          >
            <div class="n1">

              <div class="sex" :class="{on: sheep.sex === 1}">公</div>
              <p>100244(耳标号)</p>
            </div>
            <div class="n2">
              <span>项圈号:（12332）</span>
              <div></div>
              <span>18月龄</span>
            </div>
          </div>
        </van-list>
      </div>
    </div>
    <div class="btn">
      确定（15）
    </div>
  </div>
</template>

<script>
import { List, Checkbox, CheckboxGroup } from 'vant'
export default {
  components: {
    [List.name]: List,
    [Checkbox.name]: Checkbox,
    [CheckboxGroup.name]: CheckboxGroup
  },
  name: 'CheckSheep',
  data() {
    return {
      navs: [
        { id: 1, name: '羊圈名称11', check: true },
        { id: 2, name: '羊圈名称22羊圈名称22羊圈名称22', check: false },
        { id: 3, name: '羊圈名称33', check: false },
        { id: 4, name: '羊圈名称44', check: false }
      ],
      sheeps: [
        { id: 1, name: '100244', name2: '12245', age: '18月龄', sex: 1, check: true },
        { id: 2, name: '100244', name2: '12245', age: '18月龄', sex: 2, check: false },
        { id: 3, name: '100244', name2: '12245', age: '18月龄', sex: 2, check: true },
        { id: 4, name: '100244', name2: '12245', age: '18月龄', sex: 1, check: false }
      ],
      loading: true,
      finished: true,
      currentNav: 0 // 当前选中侧边栏
    }
  },
  mounted() {},
  methods: {
    // 选择耳标号
    handleCheckNo(index) {
      this.sheeps[index].check = !this.sheeps[index].check
    },
    // 侧边栏选择
    handleCheckNav(index) {
      this.currentNav = index
    },
    // 选择框
    handleCheckBox({ check }) {
      this.sheeps.forEach(ele => {
        ele.check = check
      })
    }
  }
}
</script>
<style lang='scss' scoped>
.checkSheep {
  display: flex;
  height: calc(100vh - 50px);
  .btn{
    width:100%;
    height: 50px;
    background-color: #fff;
    line-height: 50px;
    text-align: center;
    font-size: 16px;
    color:#37B5B5;
    position: fixed;
    left:0;
    bottom:0;
    box-shadow:0  5px 10px rgba(0,0,0,0.5);
  }
  .left {
    width: 165px;
    height: 100%;
    overflow-y: auto;
    background-color: #f7f7f7;
    .navs {
      display: flex;
      height: 50px;
    }
    .checkbox {
      width: 20%;
      display: flex;
      height: 100%;
      align-items: center;
    }
    .checkbox.on{
      background-color: #fff;
    }
    .nav_item {
      width: 80%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-right: 10px;
      box-sizing: border-box;
      color:#999999;
      p {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 14px;
        text-align: left;
      }
      .bian {
        width: 10px;
        height: 20px;
        opacity: 0;
      }
      .bian.on {
        opacity: 1;
      }
      div:last-child {
        // justify-content: space-between;
        justify-content: space-around;
      }
    }
    .nav_item.on {
      background-color: #fff;
      color: #333333;
    }
  }
  .right {
    width: calc(100vw - 145px);
    background-color: #fff;
    height: 100%;
    overflow-y: auto;
    .title {
      padding: 15px;
      box-sizing: border-box;
      display: flex;
      justify-content: flex-end;
      color: #333;
      font-size: 14px;
      span {
        margin-left: 15px;
      }
    }
    .nos {
      padding: 0 15px;
      padding-top: 10px;
      box-sizing: border-box;
      .no_item.on {
        background-color: #f5fbfb;
        border-color: #37b5b5;
      }
      .no_item {
        width: 100%;
        height: 60px;
        padding: 8px 10px 10px 10px;
        border: 1px solid #cccccc;
        margin-bottom: 10px;
        border-radius: 6px;
        position: relative;
        z-index: 1;
        .sex {
          width: 20px;
          height: 20px;
          margin-right: 6px;
          position: absolute;
          left: 0;
          top: 0;
          z-index: 2;
          background-color: #FDF1F1;
          color: #F29D9D;
          border-radius: 0px 0px 10px 0px;
        }
        .sex.on{
           background-color: #E1F4F4;
      color: #37B5B5;
        }
        .n1 {
          display: flex;
          align-items: center;
          color: #333;
          font-size: 14px;
          margin-bottom: 6px;
          p {
            width: 100%;
            text-align: center;
          }
        }
        .n2 {
          width: 100%;
          height: 16px;
          display: flex;
          color: #999999;
          font-size: 12px;
          align-items: center;
          justify-content: space-between;
          div {
            width: 1px;
            background-color: #999999;
            height: 100%;
          }
        }
      }
    }
  }
}
</style>
